<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>TabView</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>TabView</h1>

    
        <a href="#toc" class="jump">Jump to Table of Contents</a>
    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><div class="intro">
  <p>The TabView widget is a UI control that enables the user switch between content panels.</p>

</div>
<h2 id="getting-started">Getting Started</h2>

<p>
To include the source files for TabView and its dependencies, first load
the YUI seed file if you haven't already loaded it.
</p>

<pre class="code prettyprint">&lt;script src=&quot;http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;3.4.1&#x2F;build&#x2F;yui&#x2F;yui-min.js&quot;&gt;&lt;&#x2F;script&gt;</pre>


<p>
Next, create a new YUI instance for your application and populate it with the
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
YUI will automatically load any dependencies required by the modules you
specify.
</p>

<pre class="code prettyprint">&#x2F;&#x2F; Create a new YUI instance and populate it with the required modules.
YUI().use(&#x27;tabview&#x27;, function (Y) {
    &#x2F;&#x2F; TabView is available and ready for use. Add implementation
    &#x2F;&#x2F; code here.
});</pre>


<p>
For more information on creating YUI instances and on the
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
documentation for the <a href="../yui/index.html">YUI Global object</a>.
</p>

				<h2 id="anatomy">Anatomy of a TabView</h2>

                <h3 id="minimum-markup-requirement">Minimum Markup Requirement</h3>

                <p>A <code>TabView</code> consists of a list of links that target a content element.</p>
                <p>The basic markup needed to create from HTML is the following:</p>

<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#foo&quot;&gt;foo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#bar&quot;&gt;bar&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#baz&quot;&gt;baz&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
    &lt;&#x2F;ul&gt;
    &lt;div&gt;
        &lt;div id=&quot;foo&quot;&gt;foo content&lt;&#x2F;div&gt;
        &lt;div id=&quot;bar&quot;&gt;bar content&lt;&#x2F;div&gt;
        &lt;div id=&quot;baz&quot;&gt;baz content&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


                <h3 id="rendered-markup">Rendered Markup</h3>
<p>After a <code>TabView</code> is rendered, the final markup becomes:

<pre class="code prettyprint">&lt;div class=&quot;yui3-widget yui3-tabview&quot;&gt;
    &lt;div id=&quot;demo&quot; class=&quot;yui3-tabview-content&quot;&gt;
        &lt;ul class=&quot;yui3-tabview-list&quot;&gt;
            &lt;li class=&quot;yui3-tab yui3-widget yui3-tab-selected&quot;&gt;
                &lt;a href=&quot;#foo&quot; class=&quot;yui3-tab-label yui3-tab-content&quot;&gt;foo&lt;&#x2F;a&gt;
            &lt;&#x2F;li&gt;
            &lt;li class=&quot;yui3-tab yui3-widget&quot;&gt;
                &lt;a href=&quot;#bar&quot; class=&quot;yui3-tab-label yui3-tab-content&quot;&gt;bar&lt;&#x2F;a&gt;
            &lt;&#x2F;li&gt;
            &lt;li class=&quot;yui3-tab yui3-widget&quot;&gt;
                &lt;a href=&quot;#baz&quot; class=&quot;yui3-tab-label yui3-tab-content&quot;&gt;baz&lt;&#x2F;a&gt;
            &lt;&#x2F;li&gt;
        &lt;&#x2F;ul&gt;
        &lt;div class=&quot;yui3-tabview-panel&quot;&gt;
            &lt;div id=&quot;foo&quot; class=&quot;yui3-tab-panel&quot;&gt;foo content&lt;&#x2F;div&gt;
            &lt;div id=&quot;bar&quot; class=&quot;yui3-tab-panel&quot;&gt;bar content&lt;&#x2F;div&gt;
            &lt;div id=&quot;baz&quot; class=&quot;yui3-tab-panel&quot;&gt;baz content&lt;&#x2F;div&gt;
        &lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


                <h2 id="instantiating">Creating and Configuring a TabView</h2>
                <p>A <code>TabView</code> instance can be created from existing markup on the page, or dynamically
                using JavaScript.</p>

                <h3 id="from-markup">From Existing Markup</h3>
                <p>To create from existing markup, first conform to the basic markup pattern, then create a
                new <code>TabView</code> instance, pointing to the existing <code>srcNode</code>, and render.</p>

<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#foo&quot;&gt;foo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#bar&quot;&gt;bar&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#baz&quot;&gt;baz&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
    &lt;&#x2F;ul&gt;
    &lt;div&gt;
        &lt;div id=&quot;foo&quot;&gt;foo content&lt;&#x2F;div&gt;
        &lt;div id=&quot;bar&quot;&gt;bar content&lt;&#x2F;div&gt;
        &lt;div id=&quot;baz&quot;&gt;baz content&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;

&lt;script&gt;
YUI().use(&#x27;tabview&#x27;, function(Y) {
    var tabview = new Y.TabView({
        srcNode: &#x27;#demo&#x27;
    });

    tabview.render();
});
&lt;&#x2F;script&gt;</pre>


                <h3 id="from-js">From JavaScript</h3>
                <p>To create purely from JavaScript, all that is required is passing the <code>TabView</code>
                constructor a list of <code>children</code> containing their respective <code>label</code>
                and <content> attributes, and call render.  As with all YUI <code>Widget</code>s,
                render takes an optional container to render into, or defaults to the <code>body</code> element.</p>

<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;&lt;&#x2F;div&gt;
&lt;script&gt;
YUI().use(&#x27;tabview&#x27;, function(Y) {
    var tabview = new Y.TabView({
        children: [{
            label: &#x27;foo&#x27;,
            content: &#x27;&lt;p&gt;foo content&lt;&#x2F;p&gt;&#x27;
        }, {
            label: &#x27;bar&#x27;,
            content: &#x27;&lt;p&gt;bar content&lt;&#x2F;p&gt;&#x27;
        }, {
            label: &#x27;baz&#x27;,
            content: &#x27;&lt;p&gt;baz content&lt;&#x2F;p&gt;&#x27;
        }]
    });

    tabview.render(&#x27;#demo&#x27;);
});
&lt;&#x2F;script&gt;</pre>


            <h2 id="skinning">Skinning TabView</h2>
            <p>The <code>TabView</code> comes with a basic skin by default.  This can be easily
            customized using the rich set of <a href="#rendered-markup">classNames</a>.</p>
            <p>For a more polished look and feel, we also ship with the "sam skin", which can 
            be applied by adding the <code>yui3-skin-sam</code> className to some ancestor:</p>

<pre class="code prettyprint">&lt;body class=&quot;yui3-skin-sam&quot;&gt;
...
&lt;div id=&quot;demo&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#foo&quot;&gt;foo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#bar&quot;&gt;bar&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#baz&quot;&gt;baz&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
    &lt;&#x2F;ul&gt;
    &lt;div&gt;
        &lt;div id=&quot;foo&quot;&gt;foo content&lt;&#x2F;div&gt;
        &lt;div id=&quot;bar&quot;&gt;bar content&lt;&#x2F;div&gt;
        &lt;div id=&quot;baz&quot;&gt;baz content&lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
...
&lt;&#x2F;body&gt;</pre>


            <h2 id="events">TabView Events</h2>
            <p>TabViews fire the following events during operation:</p>
            <table>
            <thead>
                <tr>
                    <th>Event</th>
                    <th>When</th>
                    <th>Payload</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><code>addChild</code></td>
                    <td>a Tab is added to the TabView</td>
                    <td><code>child, index</code></td>
                </tr>
                <tr>
                    <td><code>removeChild</code></td>
                    <td>a Tab is removed from the TabView</td>
                    <td><code>child, index</code></td>
                </tr>
                <tr>
                    <td><code>selectionChange</code></td>
                    <td>the selected tab changes</td>
                    <td><code>prevVal, newVal</code></td>
                </tr>
                <tr>
                    <td><code>render</code></td>
                    <td>a Tabview is rendered</td>
                    <td>Normal change event signature (<code>newVal</code>, <code>prevVal</code>, etc).  When dragging, extra event property <code>ddEvent : (drag:drag event)</code> is added</td>
                </tr>
            </tbody>
            </table>

            <p>This is not an exhaustive list.  See the <a href="http://yuilibrary.com/yui/docs/api/module_tabview.html">API docs</a> for a complete listing.</p>

</div>
        </div>

        <div id="sidebar" class="yui3-u">
            
                <div id="toc" class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Table of Contents</h2>
                    </div>

                    <div class="bd">
                        <ul class="toc">
<li>
<a href="#getting-started">Getting Started</a>
</li>
<li>
<a href="#anatomy">Anatomy of a TabView</a>
<ul class="toc">
<li>
<a href="#minimum-markup-requirement">Minimum Markup Requirement</a>
</li>
<li>
<a href="#rendered-markup">Rendered Markup</a>
</li>
</ul>
</li>
<li>
<a href="#instantiating">Creating and Configuring a TabView</a>
<ul class="toc">
<li>
<a href="#from-markup">From Existing Markup</a>
</li>
<li>
<a href="#from-js">From JavaScript</a>
</li>
</ul>
</li>
<li>
<a href="#skinning">Skinning TabView</a>
</li>
<li>
<a href="#events">TabView Events</a>
</li>
</ul>
                    </div>
                </div>
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="This example shows how to create a TabView wigdet from existing HTML.">
                                        <a href="tabview-basic.html">TabView from Existing Markup</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example shows how to create a TabView wigdet from JavaScript.">
                                        <a href="tabview-fromjs.html">Dynamic TabView from JavaScript</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example shows how to add and remove Tabs.">
                                        <a href="tabview-add-remove.html">Adding and Removing Tabs</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example shows how to load tab content remotely using a YQL plugin.">
                                        <a href="tabview-yql.html">Loading Tab Content</a>
                                    </li>
                                
                            
                                
                            
                        </ul>
                    </div>
                </div>
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples That Use This Component</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                                    <li data-description="Demonstrates how to add browser history support to a TabView widget using the History Utility.">
                                        <a href="../history/history-tabview.html">History + TabView</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
